/*     */ package com.iris.egrant.grid.utils;
/*     */ 
/*     */

import com.iris.egrant.orm.hibernate.HibernateDao;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import com.iris.egrant.utils.ConditionContainer;
import org.apache.commons.collections.CollectionUtils;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class PageQueryHanlder
/*     */ {
/*     */   public static final String MODE_QL = "ql";
/*     */   public static final String MODE_HQL = "hql";
/*     */   public static final String MODEL_SQL = "sql";
/*  34 */   private final StringBuilder tempql = new StringBuilder(); private String ql;
/*  35 */   private List<Object> conditionList = new ArrayList(); private String rowsCountQl;
/*  36 */   private Map<String, Object> conditionMap = new HashMap<String, Object>();
/*     */   private String qlmode;
/*     */   
/*     */   public void setQl(StringBuilder ql) {
/*  40 */     this.ql = ql.toString();
/*     */   }
/*     */   
/*     */   public String getQl() {
/*  44 */     return this.ql;
/*     */   }
/*     */   
/*     */   public String getRowsCountQl() {
/*  48 */     return this.rowsCountQl;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public List<Object> getParams() {
/*  57 */     return this.conditionList;
/*     */   }
/*     */   
/*     */   public Map<String, Object> getParamsInMap() {
/*  61 */     return this.conditionMap;
/*     */   }
/*     */   
/*     */   public void addParamInMap(String queryKey, Object queryValue) {
/*  65 */     this.conditionMap.put(queryKey, queryValue);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void setQlMode(String qlmode) {
/*  74 */     this.qlmode = qlmode;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public PageQueryHanlder addQlSegment(String segment) {
/*  84 */     this.tempql.append(segment);
/*  85 */     return this;
/*     */   }
/*     */   
/*     */   public PageQueryHanlder addQlSegment(StringBuilder segment) {
/*  89 */     return addQlSegment(segment.toString());
/*     */   }
/*     */   
/*     */   public void internalDeal(ConditionContainer conditionContainer) {
/*  93 */     this.rowsCountQl = this.tempql.toString();
/*  94 */     boolean pinyi = conditionContainer.isPinyin();
/*  95 */     if (conditionContainer.getSortItem() != null && conditionContainer.getSortType() != null) {
/*  96 */       if (pinyi) {
/*  97 */         addQlSegment(" order by nlssort(" + conditionContainer.getSortItem() + ",'NLS_SORT=SCHINESE_PINYIN_M') ").addQlSegment(" ").addQlSegment(conditionContainer.getSortType());
/*     */       }
/*     */       else {
/*     */         
/* 101 */         addQlSegment(" order by ").addQlSegment(conditionContainer.getSortItem()).addQlSegment(" ").addQlSegment(conditionContainer.getSortType());
/*     */       } 
/*     */     }
/*     */     
/* 105 */     this.ql = this.tempql.toString();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void addParam(Object queryParam) {
/* 114 */     this.conditionList.add(queryParam);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public PageContainer loadOut(HibernateDao hibernateDao, ConditionContainer conditionContainer) {
/* 126 */     internalDeal(conditionContainer);
/* 127 */     PageContainer pageContainer = new PageContainer();
/*     */     
/* 129 */     Integer totalRowsCount = null;
/* 130 */     if (CollectionUtils.isNotEmpty(this.conditionList)) {
/* 131 */       totalRowsCount = hibernateDao.getTotalRowCount(this.rowsCountQl, this.conditionList, this.qlmode);
/*     */     } else {
/* 133 */       totalRowsCount = hibernateDao.getTotalRowCount(this.rowsCountQl, this.conditionMap, this.qlmode);
/*     */     } 
/* 135 */     pageContainer.setTotalCount(totalRowsCount);
/* 136 */     if (totalRowsCount.intValue() != 0) {
/* 137 */       List<Map<String, Object>> dataList = null;
/* 138 */       if (this.qlmode.equals("sql")) {
/* 139 */         if (CollectionUtils.isNotEmpty(this.conditionList)) {
/* 140 */           dataList = hibernateDao.getGridDataInSql(this.ql, this.conditionList, conditionContainer.getStartIndex(), conditionContainer.getMaxIndex());
/*     */         } else {
/*     */           
/* 143 */           dataList = hibernateDao.getGridDataInSql(this.ql, this.conditionMap, conditionContainer.getStartIndex(), conditionContainer.getMaxIndex());
/*     */         }
/*     */       
/*     */       }
/* 147 */       else if (CollectionUtils.isNotEmpty(this.conditionList)) {
/* 148 */         dataList = hibernateDao.getGridDataInQl(this.ql, this.conditionList, conditionContainer.getStartIndex(), conditionContainer.getMaxIndex());
/*     */       } else {
/*     */         
/* 151 */         dataList = hibernateDao.getGridDataInQl(this.ql, this.conditionMap, conditionContainer.getStartIndex(), conditionContainer.getMaxIndex());
/*     */       } 
/*     */ 
/*     */       
/* 155 */       Grid grid = new Grid();
/* 156 */       grid.setData(dataList);
/* 157 */       pageContainer.setGrid(grid);
/*     */     } else {
/* 159 */       Grid grid = new Grid();
/* 160 */       grid.setData(new ArrayList<Map<String, Object>>());
/* 161 */       pageContainer.setGrid(grid);
/*     */     } 
/* 163 */     return pageContainer;
/*     */   }
/*     */ }


/* Location:              D:\文件kjt\WEB-INF\lib\egrant-core-2.2.20240205.1659.jar!\com\iris\egrant\gri\\utils\PageQueryHanlder.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       1.1.3
 */